﻿public static class ListExtensions
{
    public static List<TTarget> ConvertTo<TSource, TTarget>(
        this List<TSource> decimals)
    {
        var result = new List<TTarget>();
        foreach (var item in decimals)
        {
            TTarget itemAfterCasting = (TTarget)Convert.ChangeType(
                item, typeof(TTarget));
            result.Add(itemAfterCasting);
        }

        return result;
    }

    public static void AddToFront<T>(this List<T> list, T item)
    {
        list.Insert(0, item);
    }

    static IEnumerable<T> CreateCollectionOfRandomLength<T>(int maxLength) where T : new()
    {
        var length = new Random().Next(maxLength + 1);
        var result = new List<T>();
        for (int i = 0; i < length; i++)
        {
            result.Add(new T());
        }

        return result;
    }
}